package com.hospital.yygh.hosp.controller;

import com.hospital.yygh.common.result.Result;
import com.hospital.yygh.hosp.service.HospitalService;
import com.hospital.yygh.model.hosp.Hospital;
import com.hospital.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(tags = "医院管理")
@RestController
@RequestMapping("admin/hosp/hospital")
//@CrossOrigin 因为使用了spring-gateway网关替代了Nginx，所以这里需要注释掉，不需要了
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;

    /**
     * 医院列表(条件查询分页)
     *
     * @param page
     * @param limit
     * @param hospitalQueryVo
     * @return
     */
    @ApiOperation("医院列表(条件查询分页)")
    @GetMapping("list/{page}/{limit}")
    public Result listHosp(@PathVariable Integer page,
                           @PathVariable Integer limit,
                           HospitalQueryVo hospitalQueryVo) { // 将查询的条件参数封装到了HospitalSetQueryVo中
        // 此时医院的数据存在于mongodb中
        Page<Hospital> pageModel = hospitalService.selectHospPage(page, limit, hospitalQueryVo);
        return Result.ok(pageModel);
    }

    /**
     * 更新医院的上限状态
     *
     * @param id
     * @param status
     * @return
     */
    @ApiOperation("更新医院的上限状态")
    @GetMapping("updateHospStatus/{id}/{status}")
    public Result updateHospStatus(@PathVariable("id") String id,
                                   @PathVariable("status") Integer status) {
        hospitalService.updateStatus(id, status);
        return Result.ok();
    }

    /**
     * 查询医院详情
     *
     * @param id
     * @return
     */
    @ApiOperation("查询医院详情")
    @GetMapping("showHospDetail/{id}")
    public Result showHospDetail(@PathVariable("id") String id) {
        // 为了方便后续取值方便，此处查询不用Hospital接收，而是放在集合里面
        Map<String, Object> map = hospitalService.getHospById(id);
        return Result.ok(map);
    }


}
